import request from "@/utils/request";
import service from "@element-plus/icons/lib/Service";


/**
 * 新增用户
 * @param {} data
 * @returns
 */
export function addUserAPI(data) {
    return request({
        url: '/user/save',
        method: 'post',
        data: data
    })
}
export function addUser(data) {
    return request({
        url: '/user/addUser',
        method: 'post',
        data: data
    })
}

export function getAnnouncementList(data) {
    return request({
        url: '/user/getAnnouncementList',
        method: 'post',
        data: data
    })
}


/**
 * 更新用户信息
 * @param {} data
 * @returns
 */
export function updateUserAPI(data) {
    return request({
        url: '/user/update',
        method: 'put',
        data: data
    })
}


/**
 * 删除用户
 * @returns
 */
export function deleteUserAPI(id) {
    return request({
        url: `/user/delete/${id}`,
        method: 'delete',
    })
}

/**
 * 判断用户是否是管理员
 */

export function checkIsAdmin() {
    return request({
        url: '/user/getUserType',
        method: 'post'
    })

}

/**
 * 获取用户信息
 */

export function getUserInfo() {
    return request({
        url: '/user/getUserInfo',
        method: 'post'
    })
}
// 个人信息获取用户
export function getUserList(data) {
    return request({
        url: '/user/getUser',
        method: 'post',
        data: data
    })
}

/**
 * 更新用户信息
 */

export function updateUserInfo(form) {
    return request({
        url: '/user/updateUserInfo',
        method: 'post',
        data: form
    })
}export function checkForget(form) {
    return request({
        url: '/user/checkForget',
        method: 'post',
        data: form
    })
}

/**
 * 更新用户信息
 */

export async function uploadPic(files) {
    let file = new FormData();
    file.append('file', files);
    let res = await request({
        url: '/public/uploadPic',
        method: 'post',
        data: file,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
    return res.data
}

/**
 * 获取全部菜单列表
 */

export function getAllMenu() {
    return request({
        url: '/user/getAllMenu',
        method: 'post'
    })
}

/**
 * 获取用户菜单权限
 */

export function getMenuRole() {
    return request({
        url: '/user/getMenuRole',
        method: 'post'
    })
}

/**
 * 查找用户
 * @returns
 */
export function getUserListByType(queryParams) {
    return request({
        url: '/user/getUserList',
        method: 'post',
        params: queryParams
    })
}export function setRoleById(queryParams) {
    return request({
        url: '/user/setRoleById',
        method: 'post',
        params: queryParams
    })
}export function batchDelete(data) {
    return request({
        url: '/user/batchDelete',
        method: 'post',
        data: data
    })
}

/**
 * 查找用户
 * @returns
 */
export function updateRoleMenu(data) {
    return request({
        url: '/user/updateRoleMenu',
        method: 'post',
        data: data
    })
}

export function getMenuList(role) {
    return request({
        url: '/user/getMenuList',
        method: 'post',
        params: {role: role}
    })
}